<?php
$con=mysqli_connect("localhost","root","youhanmo1997");
if(!$con){
	die("error:".mysqli_errno()) ;
}  

mysqli_select_db($con,"students_management");	
$sql= "SELECT * FROM students S,courses C,course_select CS Where S.sid=CS.sid AND CS.cid=C.cid ";
foreach($_POST as $key => $value){
	if(($value!="")&&($key=="sid"||$key=="classnum")){
		$sql.="AND S.".$key."='".$value."'";
	}else if(($value!="")&&($key=="cid"||$key=="cname")){
		$sql.="AND C.".$key."='".$value."'";
	}
}

$result = mysqli_query($con,$sql);
if (!$result) {
 printf("Error: %s\n", mysqli_error($con));
 exit();
}
$arr = array();
while($row=mysqli_fetch_array($result)){
	$arr[] = $row;
}
echo json_encode($arr);
?>